package com.aaa.controller.fpa;

import cn.hutool.json.JSONConfig;
import cn.hutool.json.JSONUtil;
import com.aaa.controller.BaseController;
import com.aaa.entity.Result;
import com.aaa.entity.fpa.QuestionFpa;

import com.aaa.entity.system.PageOrder;
import com.aaa.service.fpa.QuestionFpaService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;


/**
 * 问题表(QuestionFpa)表控制层
 *
 * @author
 * @since 2022-07-08 09:27:08
 */
@RestController
@RequestMapping("fpa")
public class QuestionFpaController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    QuestionFpaService questionFpaService;

    /**
     * 跳转页面
     * @param modelAndView
     * @return
     */

    //用户查询页面
    @RequestMapping("toShowFpa.do")
    public ModelAndView toShowFpa(ModelAndView modelAndView){
        modelAndView.setViewName("fpa/showFpa");
        return modelAndView;
    }
    /**
     * 分页查询
     *
     * @param questionFpa 筛选条件
     * @param pageOrder     分页排序对象
     * @param questionFpa       条件对象
     * @return 查询结果
     */
    @RequestMapping("query.do")
    public String queryByPage(PageOrder pageOrder, QuestionFpa questionFpa) {
        Page page = questionFpaService.queryAll(pageOrder, questionFpa);
        JSONConfig jsonConfig = JSONConfig.create();
        jsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
        String jsonStr = JSONUtil.toJsonStr(success(page.getTotal(), page.getResult()), jsonConfig);
        return jsonStr;
    }

    /**
     * 按照id批量删除
     * @param id
     * @return
     */
    @RequestMapping("delete.do")
    public Result delete(int[] id) {
        boolean b = questionFpaService.deleteById(id);
        if (b) {
            return success("删除成功");
        }
        return fail("删除失败");
    }

    /**
     * 添加
     * @param questionFpa
     * @return
     */
    @RequestMapping("insert.do")
    public Result insertUser(QuestionFpa questionFpa) {
        int insert = questionFpaService.insert(questionFpa);
        if (insert > 0) {
            return success();
        } else {
            return fail();
        }
    }

    /**
     * 按照id修改
     * @param questionFpa
     * @return
     */
    @RequestMapping("update.do")
    public Result updateUser(QuestionFpa questionFpa) {
        int updateUser = questionFpaService.updateUser(questionFpa);
        if (updateUser > 0) {
            return success();
        } else {
            return fail();
        }
    }

    /**
     * 查询问题是否重复
     * @param questionFpa
     * @return
     */
    @RequestMapping("repetitionQusetion.do")
    public Result repetitionName(QuestionFpa questionFpa) {
        boolean b = questionFpaService.repetitionName(questionFpa);
        if (b ) {
            return success("问题可用");
        } else {
            return fail("问题重复");
        }
    }
}
